package com.jxwifi.cloud.quickclean.complaint;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.adapter.ConplaintAdapter;
import com.jxwifi.cloud.quickclean.app.UrlPool;
import com.jxwifi.cloud.quickclean.bean.SysDicBean;
import com.jxwifi.cloud.quickclean.model.AuzImpl;
import com.jxwifi.cloud.quickclean.okhttp.Params;

import java.util.List;

public class ComplaintPresenter {

    private Context mContext;
    private AuzImpl mAuz;
    private ComplaintView mView;

    private ConplaintAdapter mAdapter;
    private List<SysDicBean> mListBean;

    public ComplaintPresenter(Context context, ComplaintView view) {
        this.mContext = context;
        this.mView = view;
        mAuz=new AuzImpl();
    }

    public void initView() {
        mView.getOrderContent().setText("订单编号" + mView.getOrderInfo().getOrderCode());
        mView.getServiceType().setText(mView.getOrderInfo().getProductName());
        mView.getServiceTime().setText(mView.getOrderInfo().getCreateTime());
        mView.getServiceAddress().setText(mView.getOrderInfo().getAddress());
        mView.getComplaintPhone().setText(mView.getOrderInfo().getUserTell());
        mView.getMeasure().setText(mView.getOrderInfo().getAreaSize());

        mView.getComplaintList().setLayoutManager(new LinearLayoutManager(mContext));
        mView.getComplaintList().setAdapter(mAdapter = new ConplaintAdapter(R.layout.list_complaint_item));
        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.rel_list_complaint_item:
                        Intent intent = new Intent();
                        intent.setClass(mContext, ComplaintDetailsActivity.class);
                        intent.putExtra("sys_dicbean", mListBean.get(position));
                        mContext.startActivity(intent);
                        mView.onfinshs();
                        break;
                }
            }
        });
        Customer();
    }

    //投诉类型
    public void Customer() {
        Params params = new Params();
        mAuz.auzget(UrlPool.GET_SYSDIC_CUSTOMER_COMPLAINT, params, new AuzImpl.AuzListener() {
            @Override
            public void AuzSuccess(int code, String data) {
                //SysDicBean
                if (code == 0) {
                    mListBean = JSON.parseArray(data, SysDicBean.class);
                    for (int i = 0; i < mListBean.size(); i++) { //在每个实体中添加ordercode用于带到下个页面中使用
                        mListBean.get(i).setOrderCode(mView.getOrderInfo().getOrderCode());
                    }
                    mAdapter.setNewData(mListBean);
                } else {
                    mView.onCustomer();
                }
            }

            @Override
            public void AuzFailure(int errorCode, String msg) {
                mView.onFailure(errorCode, msg);
            }
        });
    }
}
